package com.csun.nusing.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * 通用型的适配器
 * BaseAdapter
 * ClassName: MyBaseAdapter 
 * @Description: TODO
 * @author fzq
 * @date 2017-10-19
 */
public abstract class MyBaseAdapter<T> extends BaseAdapter {

	protected LayoutInflater mInflater;
	protected Context mContext;
	protected List<T> mDatas;
	protected final int mItemLayoutId;

	public MyBaseAdapter(Context context, List<T> mDatas, int itemLayoutId) {
		this.mContext = context;
		mInflater = LayoutInflater.from(context);
		this.mDatas = mDatas;
		this.mItemLayoutId = itemLayoutId;
	}

	@Override
	public T getItem(int position) {
		return mDatas.get(position);
	}

	@Override
	public int getCount() {
		return (null == mDatas) ? 0 : mDatas.size();
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		final ViewHolder viewHolder = getViewHolder(position, convertView,
				parent);
			convert(viewHolder, position,getItem(position));
		return viewHolder.getConvertView();

	}

	public abstract void convert(ViewHolder helper,int position, T item);

	private ViewHolder getViewHolder(int position, View convertView,
			ViewGroup parent) {
		return ViewHolder.get(mContext, convertView, parent, mItemLayoutId,
				position);
	}
}
